package me.fung.wubi.worker.printer

import me.fung.wubi.base.define.table.CodeTable
import me.fung.wubi.base.define.value.CodeList
import me.fung.wubi.base.define.value.toCode
import java.io.File

class SimpleTextPrinter(
    override var outPutFile: File
) : BaseTablePrinter() {

    override fun buildContent(table: CodeTable, config: PrintConfig): String = buildString {
        CodeList.value.forEach { codeValue: String ->
            val item = table.itemOrNull(codeValue.toCode())
            if (item != null && item.isNotEmpty()) {
                if (!config.noCode) {
                    append(item.code.value)
                    append(config.codeItemSeparator)
                }
                val s = item.joinToString(config.codeItemSeparator) { word ->
                    word.value
                }
                append(s)
                append(config.lineSeparator)
            }
        }
    }
}